//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.soft.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class ZLibUtils {
    private static final Logger logger = LoggerFactory.getLogger(ZLibUtils.class);

    public ZLibUtils() {
    }

    public static byte[] compress(byte[] data) {
        Deflater compresser = new Deflater();
        compresser.setInput(data);
        compresser.finish();
        ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);

        try {
            byte[] buf = new byte[1024];
            boolean var4 = false;

            int i;
            while((i = compresser.deflate(buf)) > 0) {
                bos.write(buf, 0, i);
            }

            byte[] var5 = bos.toByteArray();
            return var5;
        } finally {
            try {
                if (bos != null) {
                    bos.close();
                    bos = null;
                }

                compresser.end();
                compresser = null;
            } catch (IOException var12) {
                var12.printStackTrace();
            }

        }
    }

    public static byte[] decompress(byte[] data) {
        Inflater decompresser = new Inflater();
        decompresser.setInput(data);
        ByteArrayOutputStream o = new ByteArrayOutputStream(data.length);

        byte[] var4;
        try {
            byte[] buf = new byte[1024];
            boolean var17 = false;

            int i;
            while((i = decompresser.inflate(buf)) > 0) {
                o.write(buf, 0, i);
            }

            byte[] var5 = o.toByteArray();
            return var5;
        } catch (Exception var15) {
            logger.error("解压异常", var15);
            var4 = new byte[0];
        } finally {
            if (o != null) {
                try {
                    o.close();
                    o = null;
                } catch (IOException var14) {
                    var14.printStackTrace();
                }
            }

            decompresser.end();
            decompresser = null;
        }

        return var4;
    }
}
